package jlib.component.animation
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.geom.Matrix;
	
	import jlib.component.animation.Animation;
	import jlib.utils.Clock;
	import jlib.utils.MatrixUtil;

	public class MatrixAnimation extends Animation {
		
		private var m_from:Matrix;
		private var m_to:Matrix;
		private var m_mat:Matrix;
		private var m_bAutoReset:Boolean;
		private var m_bAutoReverse:Boolean;
		// MatrixAnimation.set(duration, {to:,from:,}).setOnComplete(onComplete);

		public function MatrixAnimation($target:DisplayObject, $duration:Number, $from:Matrix, $to:Matrix, $easing:Function=null, $yoyo:Boolean=false, $autoReset:Boolean=true, $autoReverse:Boolean=false) {
			super($target, $duration, $easing, $yoyo);
			m_from = $from;
			m_to = $to;
			m_mat = new Matrix();
			m_bAutoReset = $autoReset;
			m_bAutoReverse = $autoReverse;
		}
		
		override public function start($param:*=null):void {
			if(i_bRegisted && m_bAutoReverse) reverse();
			regist();
			i_bStop = false;
			if(m_bAutoReset) reset();
		}
		
		override public function move($interpolate:*): void {
			m_mat.identity();
			if(i_yoyo) $interpolate = Math.sin(Math.PI*$interpolate);
			if(i_easing != null) $interpolate = i_easing($interpolate, 0, 1, 1);
			MatrixUtil.interpolate2(m_mat, m_from, m_to, $interpolate);
			i_target.transform.matrix = m_mat;
		}
	}
}